﻿/*
  @Description:编辑钥匙js
  @Author:zb,yangpl
  @Date:2014-07-19 
*/

var GetKeyDataByKeyIdModel = {};
//智能提示方法验证是否从下拉框选择
GetKeyDataByKeyIdModel.intellisenseVerify = function (ele, hid) {
    $(ele).blur(function () {
        var tempTxtKeyLocation = $(ele);
        if ($(hid).val().length < 1) {
            if (tempTxtKeyLocation.next().attr("class") != "wrong") {
                tempTxtKeyLocation.addClass("checkError");
                tempTxtKeyLocation.after(agencyVerify.greatErrorHtml(tempTxtKeyLocation, '请从下拉框选择!'));
            }

        } else {
            tempTxtKeyLocation.removeClass("checkError");
            if (tempTxtKeyLocation.next().attr("class") == "wrong") {
                tempTxtKeyLocation.next().remove();
            }
        }
    });
};

GetKeyDataByKeyIdModel.init = function () {
    //数据非空验证
    agencyVerify.notNullInput(null, "#txtpropertykeyno", false, "blur");
    agencyVerify.notNullInput(null, "#txtKeyDateTime", false, "blur");
    //必须是英文字母
    agencyVerify.notNullInput(null, "#txtDeptBrief", true, "blur");
    agencyVerify.checkBrief(null, "#txtDeptBrief", true, "blur");
    agencyVerify.notNullInput(null, "#txtKeyDateTimeUpdata", false, "blur");
    agencyVerify.nonnegativeIntInput("#txtMobileUpdata", false);
    agencyVerify.mobileInput(null, "#txtMobileUpdata", false, "blur");
    GetKeyDataByKeyIdModel.intellisenseVerify("#txtKeyLocationUpdata", "#hidKeyLocationDepartmentKeyId");
    GetKeyDataByKeyIdModel.intellisenseVerify("#txtEmployeeNameUpdata", "#hidEmployeeKeyIdUpdata");


    //验证钥匙编号是否重复
    agencyVerify.NoInputNameSame(null, "#txtpropertykeyno", "blur", "钥匙编号重复", "/property/check-property-keyno");
  
    //具体位置智能提示
    var option = {
        departmentSelector: "#txtKeyLocationUpdata",
        departmentIDSelector: "#hidKeyLocationDepartmentKeyId",
        employeeSelector: "#txtEmployeeNameUpdata",
        employeeIDSelector: "#hidEmployeeKeyIdUpdata",
        exceptMe: false,
        hasPublicAccount: "private",
        EmployeeDefault: "请选择登记人",
        departmentDefault: "请选择具体分行",
        isAlone: true,
        employeeToDep: false,
        returnFun: function (a) {
            $("#txtEmployeeNameUpdata").focus();
            if (a.Mobile) {
                $("#divUpdataKeyUpdata #txtMobileUpdata").val(a.Mobile);
            } else {
                 $("#divUpdataKeyUpdata #txtMobileUpdata").val("");
            }
            if (a.DepartmentName) {
                $("#divUpdataKeyUpdata #txtDeptBrief").val(a.DepartmentBrief);
                $("#divUpdataKeyUpdata #txtKeyLocationUpdata").val(a.DepartmentName);
            } else {
                $("#divUpdataKeyUpdata #txtDeptBrief").val("");
                 $("#divUpdataKeyUpdata #txtKeyLocationUpdata").val("");
            }
            $("#hidKeyLocationDepartmentKeyId").val(a.DepartmentKeyId);
            $("#hidKeyPersonDepartmentKeyId").val(a.DepartmentKeyId);
        },
        //部门选择后的数据
        departmentReturnFun: function (a) {
            $("#txtKeyLocationUpdata").focus();
            if (a.DepartmentBrief) {
                $(".aui_dialog #txtDeptBrief").val(a.DepartmentBrief);
            } else {
                $(".aui_dialog #txtDeptBrief").val("");
            }
        }
    }
    EmployeePrompt.DepartmentAndEmployeeChoose(option);
    EmployeePrompt.getDepartAndEmployeeByInput(null, null, "txtEmployeeNameUpdata2", "hidEmployeeKeyIdUpdata2", false, 'private', 1, null, null, "请选择登记人");

    $.inputStatistics("txtRemarkUpdata",200);
};